<template>
    <div id="body-padding">
        <p id="p">回复 
            <span v-if="reply.name">{{reply.name}}</span>
        </p>
        <textarea v-model.trim='txt' cols="30" rows="10"></textarea>
        <button id="btn" @click="btnClick">回复</button>
    </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
    data(){
        return {
            txt:'',
        }
    },
    computed:{
        ...mapState([
            "reply"
        ])
    },
    methods:{
        mount(){
            var data = {
                repID:this.$route.params.uid,
                logID:this.$route.params.id
            };
            this.$store.dispatch("replyID",data);
        },
        btnClick(){
            console.log(this.txt);
            if(!this.txt){
                this.layer.msg("随便说点什么")
                return;
            }
            var data = {
                replyID:this.$route.params.uid,
                replyName:this.reply.name,
                logID:this.$route.params.id,
                content:this.txt,
            };
            this.http.get("/reply/add",{params:data})
            .then(res=>{
                if(res.data.err==5){
                    window.location.href = "#/login";
                    return;
                }
                this.layer.msg(res.data.msg);
                
                if(res.data.err==0){
                    window.location.href = "#/reply/"+this.$route.params.id;
                    this.txt="";
                }
            })
        }
    },
    activated(){
        this.mount();
    }

}
</script>

<style scoped>

</style>